package com.jereh.wymusicapplication.activity.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.jereh.wymusicapplication.R;
import com.jereh.wymusicapplication.activity.Base.BaseActivity;
import com.jereh.wymusicapplication.activity.adapter.FragmentListAdapter;
import com.jereh.wymusicapplication.activity.fragment.DanQuFragment;
import com.jereh.wymusicapplication.activity.fragment.GeShouFragment;
import com.jereh.wymusicapplication.activity.fragment.WenJianJiaFrament;
import com.jereh.wymusicapplication.activity.fragment.ZhuanJiFragment;

import java.util.ArrayList;
import java.util.List;

public class BenDiActivity extends BaseActivity implements View.OnClickListener {
    private TabLayout tab;
    private ViewPager viewPager;
    private DanQuFragment danQuFragment;
    private GeShouFragment geShouFragment;
    private ZhuanJiFragment zhuanJiFragment;
    private WenJianJiaFrament wenJianJiaFrament;
    private FragmentListAdapter adapter;
    private SwipeRefreshLayout refresh;
    private List<Fragment> fList=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_ben_di);
        findViewById(R.id.back).setOnClickListener(this);
        tab= (TabLayout) findViewById(R.id.tab);
        viewPager= (ViewPager) findViewById(R.id.viewPager);

        //给viewPager添加Fragment
        initViewByFragment();



    }

    private void initViewByFragment() {
        danQuFragment =new DanQuFragment();
        fList.add(danQuFragment);
        geShouFragment=new GeShouFragment();
        fList.add(geShouFragment);
        zhuanJiFragment =new ZhuanJiFragment();
        fList.add(zhuanJiFragment);
        wenJianJiaFrament =new WenJianJiaFrament();
        fList.add(wenJianJiaFrament);
        adapter=new FragmentListAdapter(getSupportFragmentManager(),fList);
        viewPager.setAdapter(adapter);
        tab.setupWithViewPager(viewPager);
        incount();
    }

    private void incount() {
        tab.getTabAt(0).setCustomView(getName(0));
        tab.getTabAt(1).setCustomView(getName(1));
        tab.getTabAt(2).setCustomView(getName(2));
        tab.getTabAt(3).setCustomView(getName(3));
    }
    private TextView getName(int position){
        TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_text_model,null);
        String[] names={"单曲","歌手","专辑","文件夹"};
        textView.setText(names[position]);
        return textView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
        }
    }

    @Override
    public View getChildContentView() {
        View view =LayoutInflater.from(this).inflate(R.layout.activity_ben_di,null);

        return view;
    }
    @Override
    public void startActivity(Intent intent){
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);//设置切换没有动画，用来实现活动之间的无缝切换
        super.startActivity(intent);
    }
}
